<template>
  <div>
    <h1>动画</h1>
    <span id="test">动画组件</span>
    <button @click="onClick">2d动画</button>
    <button @click="onClick2">3d动画</button>
    <div :class="['box',active ? 'box-active':'',active2 ? 'box-active2' : '']">实例</div>
    <button @click="isShow = !isShow">点击</button>
    <transition name="fade">
      <div v-if="isShow">动画</div>
    </transition>
    <Switch />
  </div>
</template>

<script>
import Switch from "./homework/Switch.vue";
export default {
  name: "Animation",
  components: {
    Switch
  },
  data() {
    return {
      active: false,
      active2: false,
      isShow: true
    };
  },
  methods: {
    onClick() {
      // 执行动画
      this.active = !this.active;
    },
    onClick2() {
      this.active2 = !this.active2;
    }
  },
  beforeCreate() {
    console.log("beforeCreate", this.isShow, document.getElementById("test"));
  },
  created() {
    console.log("created", this.isShow, document.getElementById("test"));
    //发起http请求
    this.$http.get("/info").then(res => {
      console.log(res);
    });
  },
  beforeMount() {
    console.log("beforeMount", this.isShow, document.getElementById("test"));
  },
  mounted() {
    console.log("mounted", this.isShow, document.getElementById("test"));
  },
  beforeUpdate() {
    console.log("beforeUpdate", this.isShow, document.getElementById("test"));
  }
};
</script>

<style scoped>
.box {
  width: 100px;
  height: 100px;
  background-color: rgb(22, 157, 219);
  /* transition: width 2s, background-color 1s, transform 2s, border-radius 2s; */
  transition: all 2s;
  border-radius: 10px;
}

.box:hover {
  /* width: 400px; */
  background-color: rgb(247, 124, 76);

  transform: translate(100px, 100px) scale(2, 2) rotate(180deg);
}

.box-active {
  transform: translate(300px, 0) rotate(360deg);
  border-radius: 50px;
  background-color: rgb(101, 91, 255);
}
.box-active2 {
  transform: rotateX(180deg);
}

.fade-enter-active,
.fade-leave-active {
  transition: all 1.5s;
  opacity: 1;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>